#coding=utf-8
__author__ = 'liubin'

from project.tools import Base
from sqlalchemy import Column, Integer, String, BigInteger, ForeignKey, Boolean, Text, Numeric
from sqlalchemy.orm import relationship, backref
from sqlalchemy.sql.expression import text
from project.tools import JsonpickleMixin
from base import BaseModel


class Inventory(BaseModel, Base):
    """
    材料表
    采购回来的布料
    """
    __tablename__ = 't_inventory'
    textileId = Column('textile_id', BigInteger, ForeignKey('m_textile.id'), nullable=False)
    length = Column('length', Numeric, default=0, server_default=0)
    weight = Column('weight', Numeric, default=0, server_default=0)
    rate = Column('rate', Numeric, default=0, server_default=0)
    unitId = Column('unit_id', BigInteger, ForeignKey('m_unit.id'), nullable=False)
    isDeleted = Column('is_deleted', Boolean, server_default=text('FALSE'))

    def __init__(self, data=None):
        """
        初始化
        :param data:
        :return:
        """
        if data:
            self.textileId = data.get('textileId')
            self.length = data.get('length')
            self.weight = data.get('weight')
            self.rate = data.get('rate')
            self.unitId = data.get('unitId')